<script setup>
import { Plus } from "@element-plus/icons-vue";
import useTable from "@/utils/useTable";
import {http} from "@/api";
import router from "@/router";

/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
  openAdd,
  openEdit,
  openDelete,
  updateStatus
} = useTable({
  requestFn: http.Member,
  routerPre: 'Member',
  params: {
    nickname: '',
  }
})
const openEditOrder = (row) => {
  router.push({
    path: '/ProductOrder?member_id' + row.id,
  })
}
</script>


<template>
  <PageMain title="会员管理">
    <el-form label-suffix="：" inline>
      <el-form-item label="名称">
        <el-input v-model="searchParams.nickname" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="add-box">
      <el-button type="primary" :icon="Plus" @click="openAdd">添加</el-button>
    </div>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column label="姓名" prop="nickname">
        </el-table-column>
        <el-table-column label="手机" prop="phone">
        </el-table-column>
        <el-table-column label="头像">
          <template #default="scope">
            <div style="display: flex; align-items: center">
              <ViewImage type="image" :image-url="scope.row.avatar_url"/>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="注册时间" prop="create_time">
        </el-table-column>
        <el-table-column label="操作" width="220px">
          <template #default="scope">
            <el-button type="text" @click="openEdit(scope.row)">编辑</el-button>
<!--            <el-button type="text" @click="openEditOrder(scope.row)">历史订单</el-button>-->
            <el-button type="text" @click="openDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 50, 100, 200]"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="changeSize"
          @current-change="changePage"
      />
    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
